﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Configuration;
using KPIS.DBM;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.IDAL;

namespace KPIS.GERP.GHRMS.DAL
{
    public sealed class JobsiteLevelDAL : IJobSiteLevelDAL
    {
        IDBManager dbManager = new DBManager(SystemInfo._DataProvider, SystemInfo._ConnectionString);

        public JobsiteLevelDAL()
        {

        }
        public IList<JobSiteLevelInfo> ListJobSiteLevels(Nullable<int> Seq)
        {
            string strSQL;

            List<JobSiteLevelInfo> infoList = new List<JobSiteLevelInfo>();

            try
            {
                dbManager.Open();
                dbManager.CreateParameters(2);

                dbManager.AddParameters(0, "@DeleteRecord", SystemInfo._DeleteRecordStatus);
                dbManager.AddParameters(1, "@Seq", Seq);

                strSQL = "SELECT JOB_SITE_LEVEL_SEQ, JOB_SITE_LEVEL_NO, JOB_SITE_LEVEL_NAME"
                    + " FROM HRM_MP_JOB_SITE_LEVELS"
                    + " WHERE RECORD_STATUS not like @DeleteRecord"
                    + (Seq.HasValue ? " AND JOB_SITE_LEVEL_SEQ = @Seq" : "");

                IDataReader rdr = dbManager.ExecuteReader(CommandType.Text, strSQL);

                while (rdr.Read())
                {
                    JobSiteLevelInfo Info = new JobSiteLevelInfo(rdr.GetInt32(0)
                            , rdr.GetInt32(1)
                            , rdr.IsDBNull(2) ? "" : rdr.GetString(2));

                    infoList.Add(Info);
                }

            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.CloseReader();
                dbManager.Dispose();
            }
            return infoList;
        }        
    }
}
